package com.gzist.elderlyserviceplatform.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzist.elderlyserviceplatform.common.Result;
import com.gzist.elderlyserviceplatform.entity.dto.ListQueryPageDTO;
import com.gzist.elderlyserviceplatform.entity.po.File;
import com.gzist.elderlyserviceplatform.service.FileService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * 文件附件表
 */
@RestController
@Tag(name = "文件附件管理")
@RequestMapping("/api/admin/file")
@RequiredArgsConstructor
public class FileControllerA {

    private final FileService fileService;

    @PostMapping("/list")
    @Operation(summary = "附件信息查询列表接口")
    public Result<Page<File>> list(
            @RequestBody
            @Parameter(description = "查询参数") ListQueryPageDTO listQueryPageDTO
    ) {
        return Result.success(fileService.queryPage(listQueryPageDTO), "查询成功");
    }

    @GetMapping("/detail/{id}")
    @Operation(summary = "附件信息单个查询")
    public Result<File> detail(
            @PathVariable
            @Parameter(description = "附件id") String id
    ) {
        return Result.success(fileService.getById(id), "查询成功");
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "附件信息删除")
    public Result delete(
            @PathVariable
            @Parameter(description = "附件id") String id
    ) {
        fileService.removeById(id);
        return Result.success("删除成功");
    }

    @PostMapping("/batchDelete")
    @Operation(summary = "附件信息批量删除")
    public Result deleteBatch(
            @RequestBody
            @Parameter(description = "附件信息id集") String[] ids
    ) {
        fileService.removeByIds(Arrays.asList(ids));
        return Result.success("删除成功");
    }
}